package com.zjlanyun.erp.adapter;

import java.util.ArrayList;

import com.zjlanyun.erp.R;
import com.zjlanyun.erp.model.AddressBookModel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AddressBookAdapter extends BaseAdapter {

	private ArrayList<AddressBookModel> mList;
	private LayoutInflater mInflater;
	private int[] mColor;
	
	public final class ListItemView{
        public TextView fullname;     
        public TextView name;
        public TextView tel;
        public LinearLayout name_bg;
	}
	
	public AddressBookAdapter(Context context, ArrayList<AddressBookModel> mList, int[] color){
		this.mInflater = LayoutInflater.from(context);
		this.mList = mList;
		this.mColor = color;
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ListItemView listItemView = null;
		if(convertView == null){
			listItemView = new ListItemView();
			convertView = mInflater.inflate(R.layout.main_address_book_item, null);
			listItemView.fullname = (TextView) convertView.findViewById(R.id.fullname);
			listItemView.name = (TextView) convertView.findViewById(R.id.name);
			listItemView.tel = (TextView) convertView.findViewById(R.id.tel);
			listItemView.name_bg = (LinearLayout) convertView.findViewById(R.id.name_bg);
			convertView.setTag(listItemView);
		}else{
			listItemView = (ListItemView) convertView.getTag();
		}
		
		listItemView.fullname.setText(mList.get(position).getFName());
		listItemView.name.setText(mList.get(position).getSurname());
		listItemView.tel.setText(mList.get(position).getFMobilePhone());
		listItemView.name_bg.setBackgroundResource(mColor[mList.get(position).getNamebgid()]);
		return convertView;
	}

}
